<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/vue-router/dist/vue-router.js"></script>
    <style>
        .router-link-active{
            font-size: 20px;
            color: #f60;
        }
    </style>
</head>
<body>
<div id="box">
    <div>
        <router-link to="/home">主页</router-link>
        <router-link to="/news">新闻</router-link>
        <router-link to="/user">用户</router-link>
    </div>
    <div>
        <router-view></router-view>
    </div>
</div>

<template id="user">
    <div>
        <h3>我是用户信息</h3>
        <ul>
            <li><router-link to="/user/username">某个用户</router-link></li>
        </ul>
        <div>
            <router-view></router-view>
        </div>
    </div>
</template>


<script>
    //组件
    var Home = {
        template: '<h3>我是主页</h3>'
    };
    var News = {
        template: '<h3>我是新闻</h3>'
    };
    var User = {
        template: '#user'
    };
    var UserDetail = {
        template: '<div>我是某用户</div>'
    }


    //配置路由
    const routes=[
        {path: '/home',component: Home},
        {path: '/news',component: News},
        {
            path: '/user',
            component: User,
            children: [
                {path: 'username',component: UserDetail}
            ]
        },
        {path: '*', redirect: '/home'}
    ]

    //生成路由实例
    const router = new VueRouter({
        routes: routes
    })

    //挂载到vue上
    new Vue({
        router: router,
        el: '#box'
    })
</script>
</body>
</html>